package com.tongzhou.tongzhou.quot.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.tongzhou.db.exception.DBException;
import com.tongzhou.tongzhou.quot.dao.IPaperTypeDAO;
import com.tongzhou.tongzhou.quot.model.PaperType;
import com.tongzhou.tongzhou.quot.model.SearchPaperCondition;
import com.tongzhou.tongzhou.quot.model.SearchPaperTypeCondition;

public class PaperTypeAction extends ActionSupport{
	private int id;
	private PaperType paperType;
	private List<PaperType> result=null;
	private SearchPaperTypeCondition condition=null;
	
	private int pageSize ;
	private int currentPage ;
	private String orderBy ;
	private String orderByType ;
	
	private IPaperTypeDAO dao=null;
	/**
	 * 纸型列表界面
	 *@author: 彭定雄
	 *@return 
	 *@throws DBException
	 */
	public String listPaperType() throws DBException{
		checkSearchCondition();
		condition = new SearchPaperTypeCondition();
		if (currentPage == 0){
			currentPage = 1;
		}
		condition.setCurrentPage(currentPage) ;
		condition.setOrderBy(orderBy);
		condition.setOrderByType(orderByType) ;
		condition.setPageSize(pageSize) ;
	    result = dao.listPaperType(condition);
		return "listPaperType";
	} 
	
	
	/**
	 * 设置列表显示格式
	 *@author: 彭定雄
	 */
	private void checkSearchCondition(){
		if(currentPage <=0){
			currentPage = 1 ;
		}
		
		if(pageSize<=0){
			pageSize = 10 ;
		}
		
		if(orderBy==null||"".equals(orderBy)){
			orderBy = "id" ;
		}
		
		if(orderByType == null || "".equals(orderByType)){
			orderByType = "desc" ;
		}
	}
	
	/**
	 * 新增纸型
	 *@author: 彭定雄
	 *@return
	 *@throws DBException
	 */
	public String toAddPaperType() throws DBException{
		return "addPaperType";
	}
	
	public String addPaperType() throws DBException{
		dao.addPaperType(paperType);
		listPaperType();
		return "listPaperType";
	}
	
	public String deletePaperType() throws DBException{
//		dao=new UserMgrDAO();
		dao.deletePaperType(id);
		listPaperType();
		return "listPaperType";
	}
	
	public String toEditPaperType() throws DBException{
		paperType=dao.getPaperTypeById(id);
		return "editPaperType";
	}
	
	public String editPaperType() throws DBException{
		dao.updatePaperType(paperType);
		listPaperType();
		return "listPaperType";
	}


	public int getId() {
		return id;
	}


	public void setId(int id) {
		this.id = id;
	}


	public List<PaperType> getResult() {
		return result;
	}


	public void setResult(List<PaperType> result) {
		this.result = result;
	}

	public SearchPaperTypeCondition getCondition() {
		return condition;
	}


	public void setCondition(SearchPaperTypeCondition condition) {
		this.condition = condition;
	}


	public int getPageSize() {
		return pageSize;
	}


	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}


	public int getCurrentPage() {
		return currentPage;
	}


	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}


	public String getOrderBy() {
		return orderBy;
	}


	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}


	public String getOrderByType() {
		return orderByType;
	}


	public void setOrderByType(String orderByType) {
		this.orderByType = orderByType;
	}


	public IPaperTypeDAO getDao() {
		return dao;
	}


	public void setDao(IPaperTypeDAO dao) {
		this.dao = dao;
	}


	public PaperType getPaperType() {
		return paperType;
	}


	public void setPaperType(PaperType paperType) {
		this.paperType = paperType;
	}
	
}
